# coding=utf-8
##
## Author: jmdvirus@aliyun.com
##
## Create: 2019年02月14日 星期四 16时17分38秒
##

import os

prefix = "/opt/data/data/ai.cifar/cifar"

def cov(prefix):
    file = open(prefix+'/labels.txt', 'r')
    labels = file.readlines()
    for i in range(len(labels)):
        labels[i] = labels[i].strip()
    print(labels)

    target = prefix + '/train/'
    dst = './train/'
    for i in range(10):
        directory = dst + str(i)
        if not os.path.exists(directory):
            os.makedirs(directory)

    for filename in os.listdir(target):
        if not filename.endswith('.png'):
            continue
        print(filename)
        tmp = filename.split('_')
        index = labels.index(tmp[1][:-4])
        os.rename(target + filename, dst+str(index) + '/' + filename)

if __name__ == "__main__":
    cov(prefix)

